package com.acwing.partition17;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/16 18:53
 */
public class AC1660社交距离II {

    private static final int N = 1010;
    private static int[][] pairs = new int[N][2];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 1; i <= n; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            pairs[i] = new int[]{a, b};
        }
        Arrays.sort(pairs, 1, n + 1, (o1, o2) -> Integer.compare(o1[0], o2[0]));
        //找出最小感染半径
        int r = 0x3f3f3f3f, ans = 0;
        for (int i = 1; i < n; i++) {
            if (pairs[i][1] != pairs[i + 1][1]) r = Math.min(r, pairs[i + 1][0] - pairs[i][0]);
        }
        //以每一个被感染的为起点进行扩散
        for (int i = 1; i <= n; i++) {
            if (pairs[i][1] == 1) {
                ans++;
                int j = i + 1;
                while (j <= n && pairs[j][0] - pairs[j - 1][0] < r) j++;
                i = j - 1;
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
